package algorithm;

/**
 * @author apple
 * @Classname Hanoi  汉诺塔
 * @Description 递归实现汉诺塔
 * @Date 2020/3/17 10:39
 */
public class Hanoi {
    public static int count = 0;

    public static void main(String[] args) {
        hanoi(5, 'A', 'B', 'C');
        System.out.println("count="+count);
    }

    public static void hanoi(int n, char start, char transfer, char target) {
        /**只有一个盘子，直接搬到target**/
        if (n == 1) {
            System.out.println(start + "-->" + target);
            count++;
        } else {
            hanoi(n - 1, start, target, transfer);
            System.out.println(start + "-->" + target);
            count++;
            hanoi(n - 1, transfer, start, target);
        }

    }
}
